<template>
  <div class="app-container family-PingFangSC-Regular">
    <el-button type="primary" @click="addCase" class="margin-r margin-t30 margin-b10">添加案例</el-button>
    <el-table
      :data="tableData" :header-row-style="{'font-family': 'PingFangSC-Semibold','backgroundColor': '#f5f7fa','color':'#5c6065'}"
      stripe
      class="table c-width100 color-222 family-PingFangSC-Regular font-s12">
      <el-table-column
        label="名称">
        <template slot-scope="scope">
          <div class="clearfix">
            <div class="fl margin-r"><img :src="scope.row.avatar" height="80" width="80" alt=""></div>
            <div class="fl">
              <div class="margin-t10 margin-b">{{scope.row.name}}</div>
              <div>排序：{{scope.row.sort}}</div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="二维码">
        <template slot-scope="scope">
          <div class="center">
            <img :src=" scope.row.qrcodeImg" alt="" width="70px" height="70px">
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        width="300"
      align="center">
        <template slot-scope="scope">
          <b @click="editCase(scope.row.caseId)">编辑</b><span class="color-409">|</span>
          <b @click="delCase(scope.row.caseId)">删除</b>
        </template>
      </el-table-column>
    </el-table>
        <div class="block text-c">
      <!--分页组件 current-page:当前页   -->
      <!--   page-sizes:每页几条数据（选项）   -->
      <!--   page-size:每页几条数据   -->
      <!--   total:总条数   -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="listQuery.currentPage"
          :page-sizes="[10, 20, 30, 40, 50]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="listQuery.total">
        </el-pagination>
    </div>
  </div>
</template>
<script>
import { getCase, toDelCase } from '@/api/extra'
export default {
  data() {
    return {
      tableData: [],
      listLoading: false,
      listQuery: {
        // 限制条件
        currentPage: 1,
        page: 1,
        type: 'all',
        total: 0,
        limit: 10
      }
    }
  },
  created() {
    this.getSuccessCase()
  },
  methods: {
    getSuccessCase() {
      this.listLoading = true
      getCase(this.listQuery).then(res => {
        this.tableData = res.data.data.data
        this.listQuery.total = res.data.data.total
        this.listLoading = false
      })
        .catch(err => {
          console.log(err)
        })
    },
    addCase() {
      this.$router.push({ name: 'addCase' })
    },
    editCase(id) {
      this.$router.push({ path: `/successCaseLists/editCase/${id}` })
    },
    delCase(id) {
      this.$confirm('确定删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        toDelCase(id).then(res => {
        // 正确回调
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.getSuccessCase()
        })
          .catch(err => {
            console.log(err)
          })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    handleSizeChange(val) {
      // 切换每页几条数据方法
      this.listQuery.limit = val
      this.getSuccessCase()
    },
    handleCurrentChange(val) {
      // 切换当前页码的方法
      this.listQuery.page = val
      this.getSuccessCase()
    }
  }

}
</script>
<style scoped>
  .table thead {
    font-weight: 400;
    font-size: 14px;
    color: #5c6065;
    font-family: PingFangSC-Semibold;
  }
  .table thead>tr {
    background-color: #f5f7fa;
  }
</style>
